/**
 * Created by lx on 2017/10/9.
 */
/**
 * Created by lx on 2017/9/26.
 */
/**
 * Created by lx on 2017/9/25.
 */
angular.module('module.table.operation')
    .controller('TableNumInputSnController', TableNumInputSnController);
TableNumInputSnController.$inject = ['$stateParams', '$state', '$localStorage', 'TableNumService'];
function TableNumInputSnController($stateParams, $state, $localStorage, TableNumService) {

    var vm = this;
    $('.modal-backdrop ').hide(); // 初始化
    var tableid = $stateParams.tableid;

    if (!$localStorage[environmental + "shopid"]) {
        $localStorage.$reset();
        $state.go('login');
    }

    vm.saveDev = saveDev;
    vm.sureBtn = sureBtn; // 模态框
    vm.cancelBtn = cancelBtn; // 模态框

    var inputSnBtn = $("#inputsnbtn");
    function saveDev(devid) {
        inputSnBtn.attr("disabled", true);

        if (!devid) {
            vm.messageVisible = true;
            vm.message = "请输入设备号！";
            inputSnBtn.attr("disabled", false);
            return;
        }

        var data = {
            devid: devid,
            shopid: $localStorage[environmental + "shopid"],
            tableid: tableid,
        };

        TableNumService.shopDevRelation(data, function (sccData) {
            $state.go('tabledetail', {tableid: sccData.tableid});
            inputSnBtn.attr("disabled", false);
        }, function (errData) {
            vm.messageVisible = true;
            vm.message = errData.data.message + "，请重新绑定！";
            inputSnBtn.attr("disabled", false);
        })
    }

    function sureBtn() {
        vm.messageVisible = false;
    }

    function cancelBtn() {
        vm.messageVisible = false;
    }
}